//
//  AddressBook.m
//  OC5_课后作业第二次
//
//  Created by dllo on 15/10/29.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "AddressBook.h"

@implementation AddressBook





- (id)init
{
    self = [super init];
    if (self) {
        _temp = [[NSMutableArray alloc] init];
    }
    return self;
}


// 添加联系人

- (void)addPerson:(Contact *)per
{
    if ([[per name] length] == 0 || [per phonenum] == 0) {
        NSLog(@"添加失败");
    } else {
        [_temp addObject:per];
    }
}


// 获取某个分组下所有联系人

- (void)bygroup:(NSString *)groupName
{
    for (Contact *per in _temp) {
        if ([[per group] isEqualToString:groupName]) {
            [per info];
        }
    }
}


// 根据电话号码搜索联系人

- (void)bynumber:(NSInteger)number
{
    for (Contact *per in _temp) {
        if ([per phonenum] == number) {
            [per info];
        }
    }
}

//  获取所有女性联系人

- (void)bysex:(NSString *)sex
{
    for (NSInteger i = 0; i < _temp.count; i++) {
        if ([[[_temp objectAtIndex:i] sex] isEqual:sex]) {
            [[_temp objectAtIndex:i] info];
        }
    }
}

// 根据姓名删除联系人

- (void)byName:(NSString *)name
{
    for (NSInteger i = 0; i < [_temp count]; i++) {
        if ([[[_temp objectAtIndex:i] name] isEqualTo:name]) {
            [_temp removeObject:[_temp objectAtIndex:i]];
            i--;
        }
    }
}

// 删除某个分组全部联系人

- (void)delGroup:(NSString *)groupname
{
    for (NSInteger i = 0; i < _temp.count; i++) {
        if ([[[_temp objectAtIndex:i] group] isEqualTo:groupname]) {
            [_temp removeObject:[_temp objectAtIndex:i]];
        }
    }
}

// 8 展示通讯录中所有联系人

- (void)showAddressBook
{
    for (NSInteger i = 0; i < [_temp count]; i++) {
        [[_temp objectAtIndex:i] info];
    }
}









@end
